<?php

namespace App\Http\Controllers;

use App\Comment;
use App\CommentReply;
use Illuminate\Http\Request;

class CommentController extends Controller
{
    public  function reply(Request $request,Comment $comment){
        $this->validate($request,[
            'content'=>'required'
        ]);
        $reply=new CommentReply();
        $reply->comment_id=$request->comment_id;
        $reply->from_user_id=\Auth::id();
        $reply->from_user_name=\Auth::user()->name;
        $reply->from_user_thumb=\Auth::user()->thumb;
        $reply->to_user_id=$request->to_user_id;
        $reply->to_user_name=$request->to_user_name;
        $reply->content=$request->input('content');
        $comment->replys()->save($reply);

        return json_encode($reply);
    }
    public  function total_reply($comment_id){
        $res=CommentReply::where('comment_id',$comment_id)->orderBy('created_at','desc')->get();
        echo json_encode($res);
    }
}
